package be.rhok.eenzaamheidswijzer.dao;

import java.util.Collection;
import java.util.List;

public interface BaseDao<T> {
    /**
     * Find an object by its id.
     * Hits the database immediately.
     *
     * @param id the objects id
     * @return the object or null if no matching row is found
     */
    T get(Object id);

    /**
     * Throws exception if no matching row is found.
     *
     * @param id
     * @return An uninitialized proxy (no immediate db hit)
     */
    T load(Object id);

    /**
     * Returns all objects in a table
     *
     * @return List of objects
     */
    List<T> findAll();

    /**
     * Merges the given object
     *
     * @param t: the object that needs to be merged
     * @return the merged object that is returned by the database
     */
    T merge(T t);

    /**
     * Persist the given transient instance. Follows JSR-220 semantics.
     *
     * @param t: the object that needs to be persisted
     */
    void persist(T t);

    /**
     * Update the given persistent instance, associating it with the current Hibernate Session.
     *
     * @param t
     */
    void update(T t);

    /**
     * Save or update all given persistent instances, according to its id (matching the configured "unsaved-value"?).
     *
     * @param items
     */
    void saveOrUpdateAll(Collection<T> items);

    /**
     * Removes a given object from the database
     *
     * @param t object to be removed
     */
    void remove(T t);

    /**
     * Removes the given objects
     *
     * @param t Collection of objects to delete
     */
    void remove(Collection<T> t);

    /**
     * Flush all pending saves, updates and deletes to the database.
     */
    void flush();
}

